
public class RotateArray {
	
	 public int removeDuplicates(int[] A) {
	         int length=A.length;
	         
	         if(length<=2)
	        	 return length;
	         
	         int count=0;
	         for(int i=0;i<A.length-2;i++){
	        	 if(A[i+2]==A[i]){
	        		 count++;
	        	 }else{
	        		 A[i-count]=A[i];
	        	 }
	         }
	         if(A.length-2-count>=0){ 
	           A[A.length-2-count]=A[A.length-2];
	           A[A.length-1-count]=A[A.length-1];
	         }
	         for(int i=count;i>0;i--){
	        	 A[length-i]=0;
	         }
	         return length-count;
	 }
	 public static void main(String[] args) {
		new RotateArray().removeDuplicates(new int[]{1,1,1,2});
	}
}
